// 手写forEach
Array.prototype.myForEach = function (cbk, thisArg = window) {
  if (typeof cbk != "function") {
    throw new TypeError("啦啦啦");
  }
  let len = this.length;
  for (let i = 0; i < len; i++) {
    cbk.call(thisArg, this[i], i, this);
  }
};

let arr1 = [
  {
    name: "111",
  },
  {
    name: "2222",
  },
  {
    name: "3333",
  },
  {
    name: "4444",
  },
  {
    name: "5555",
  },
];
let testObj = {
  name: "张三",
};
// arr1.myForEach((item, index, lll) => {
//   console.log(item, index, lll, this);
// }, testObj);

// 手写filter

Array.prototype.myFilter = function (cbk, thisArg) {
  if (typeof cbk != "function") {
    throw new TypeError("啦啦啦");
  }
  let len = this.length;
  let res = [];
  for (let i = 0; i < len; i++) {
    if (cbk.call(thisArg, this[i], i, this)) {
      res.push(this[i]);
    }
  }
  return res;
};

arr1 = arr1.myFilter((item, index, lll) => {
  return item.name !== "111";
});
console.log(arr1);
